package com.example.order.mapper;


import com.example.model.customer.pojo.Customer;
import com.example.model.order.dto.OrdersCustonmerDTO;
import com.example.model.order.dto.OrdersDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrdersMapper {

    List<OrdersDTO> page(LocalDateTime orderDateStart, LocalDateTime orderDateEnd, String shipmentAddress, String customerName);

    void delete(List<Integer> ids);

    /**
     * 保存
     * @param OrdersCustonmerDTO
     */
    void saveCustomer(OrdersCustonmerDTO OrdersCustonmerDTO);

    void saveOrders(OrdersCustonmerDTO ordersCustonmerDTO);

    @Select("SELECT Orders.*,  customer.name, email, phone\n" +
            "FROM sm.Orders\n" +
            "INNER JOIN sm.Customer ON Orders.customer_id = Customer.customer_id where order_id = #{id};\n")
    OrdersCustonmerDTO selectById(Integer id);

    /**
     * 更新
     * @param customer
     */
    @Update("update sm.Customer set name = #{name}, email = #{email}, phone = #{phone} where customer_id=#{customerId} ")
    void updateCustonmerById(Customer customer);
    @Update("UPDATE sm.orders\n" +
            "SET order_id = #{orderId}, \n" +
            "    customer_id = #{customerId}, \n" +
            "    order_date = #{orderDate}, \n" +
            "    status = #{status}, \n" +
            "    total_amount = #{totalAmount}, \n" +
            "    shipment_address= #{shipmentAddress},\n" +
            "    customer_id = #{customerId}\n" +
            "WHERE order_id = #{orderId};")
    void updateOrdersById(OrdersCustonmerDTO ordersCustonmerDTO);
}
